<!-- pass a variable to included page -->
<%@ page import="bcared.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<% 
   String today = null;
   Today t = new Today();
   today = t.getToday();
   request.setAttribute("picture","Customer");
   request.setAttribute("title", "Customer Home"); 
   request.setAttribute("header", "Welcome " + 
   		session.getAttribute("firstname") + " " + 
   		session.getAttribute("lastname") + " from " + 
   		session.getAttribute("customername") + " : Today is " + today); 
 %>
 <%@ include file="header.jsp"%><TD width="850" vAlign="top"> 
<br />
<h2>Open Service Requests</h2><br />
			<table width=100% border=0 cellpadding=3 cellspacing=3>
			<tr>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Service Order</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Status</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Priority</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Open Date</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Service Type</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Product</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Serial Number</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Location</th>
			</tr>
 <%
 int customerid=0;
try	{
 	customerid = Integer.parseInt((session.getAttribute("customerid")+ ""));
	}
catch (Exception ex){
	response.sendRedirect("engineerhome.jsp");
	}
	
	if (request.getAttribute("customerID") != null) {
		customerid = Integer.parseInt((request.getAttribute("customerID") + ""));
 	}
 	
 ResultSet rs = null;
 ArrayList<ServiceOrder> openServiceOrders = new ArrayList<ServiceOrder>();
 String rowcolor = "whitesmoke";
 String textcolor = "black";
 String myRowColor = rowcolor;
 
 Customer c = new Customer(customerid);

 openServiceOrders = c.getOpenServiceOrders();
 
 for (int i = 0; i < openServiceOrders.size(); i++) {
  %>
	
	<tr>

	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;"><a href=ServiceOrderDetails2.jsp?SOID=<%=openServiceOrders.get(i).getSOID()%>>&nbsp;<%=openServiceOrders.get(i).getSOID()%></a></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getSOStatusDesc()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getPriorityDescription()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getOpenDate()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getServiceTypeDescription()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getProductName()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getSerialNumber()%></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=openServiceOrders.get(i).getAddress1() + "<br/>" +openServiceOrders.get(i).getCity() + ", " + openServiceOrders.get(i).getState()%></td>
	
	</tr>
				
  <%
      if (rowcolor.equals(myRowColor)) {
      		rowcolor = "white";
     		textcolor = "black";
 		 }
  		else   {
      		rowcolor = myRowColor;
      		textcolor = "black";
  		}
    }  
 %>
 </table>
 <br />
 <h2>Closed Service Orders</h2>
 	<table width=100% border=0 cellpadding=3 cellspacing=3>
    <tr>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Service Order</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Status</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Priority</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Open Date</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Close Date</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Service Type</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Product</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Serial Number</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Location</th>
			</tr>
			<%
			  ArrayList<ServiceOrder> closedServiceOrders = new ArrayList<ServiceOrder>();
			  closedServiceOrders = c.getClosedServiceOrders();
 
 for (int i = 0; i < closedServiceOrders.size(); i++) {
  %>
		
	<tr>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;"><a href=ServiceOrderDetails2.jsp?SOID=<%=closedServiceOrders.get(i).getSOID()%>>&nbsp;<%=closedServiceOrders.get(i).getSOID()%></a></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getSOStatusDesc()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getPriorityDescription()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getOpenDate()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getCloseDate()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getServiceTypeDescription()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getProductName()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getSerialNumber()%></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=closedServiceOrders.get(i).getAddress1() + "<br/>" + closedServiceOrders.get(i).getCity() + ", " + closedServiceOrders.get(i).getState()%></td>
	
	</tr>
				
  <%
      if (rowcolor.equals(myRowColor)) {
      		rowcolor = "white";
     		textcolor = "black";
 		 }
  		else   {
      		rowcolor = myRowColor;
      		textcolor = "black";
  		}
    }  
    %>
			
		</table>	
    
    <br />
 <h2>Equipment</h2>
 	<table width="100%" border=0 cellpadding=3 cellspacing=3>
    <tr>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Product Name</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Serial Number</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">In Service Date</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;">Status</th>
				<th bgcolor="#3B73B9" style="text-align:center; color:white;"></th>
			</tr>
			<%
			  ArrayList<Equipment> equipmentList = new ArrayList<Equipment>();
			  equipmentList = c.getEquipment();
 
 for (int i = 0; i < equipmentList.size(); i++) {
  %>
		
	<tr>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=equipmentList.get(i).getEquipmentID()%></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=equipmentList.get(i).getProductName()%></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=equipmentList.get(i).getSerialNumber()%></td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=equipmentList.get(i).getInServiceDate()%>&nbsp;</td>
	<td bgcolor="<%=rowcolor%>" style="text-align:center; color:<%=textcolor%>;">&nbsp;<%=equipmentList.get(i).getStatusDesc()%>&nbsp;</td>
	<td>
		<%if (equipmentList.get(i).getStatusID() == 1) { %>
			<form action="newserviceorder.jsp" method="post">
				<input type="submit" name="ticket" value="New Ticket"/>
				<input type="hidden" name="equipmentID" value="<%=equipmentList.get(i).getEquipmentID()%>"/>
				<input type="hidden" name="customerID" value="<%=customerid%>"/>
			</form>
		<%} %>
	</td>
	
	</tr>
				
  <%
      if (rowcolor.equals(myRowColor)) {
      		rowcolor = "white";
     		textcolor = "black";
 		 }
  		else   {
      		rowcolor = myRowColor;
      		textcolor = "black";
  		}
    }  
    %>
			
		</table>	
		
    
    <%
     c.closeConnection();
 %>
 
 

 
</html>
  		
  		
  		
  		
  		